<template>
  <p-card :bordered="false">
    <!-- 查询区域 -->
    <!-- 查询区域 -->

    <div class="table-page-search-wrapper">
      <p-form layout="inline" @keyup.enter.native="searchQuery">
        <p-row :gutter="24">
          <p-col :xl="8" :lg="7" :md="8" :sm="24">
            <p-form-item label="生产工单" >
              <p-select  
                showSearch="true"
                placeholder="Select a person"
                option-filter-prop="children"
                :filter-option="filterOption"
                @change="handleChange"
                v-model="active"
                default-value="请选择"
              >
                <p-select-option
                  @click="QueryData(value)"
                  :key="value.productionno"
                  v-for="value in mes_filed_type"
                >{{value.productionno}}</p-select-option>
              </p-select> 
            </p-form-item>
          </p-col>
          <p-col :xl="8" :lg="7" :md="8" :sm="24">
            <p-form-item label="产品编码">
              <p-input readonly placeholder="产品编码" disabled v-model="queryParam.mcode"></p-input>
            </p-form-item>
          </p-col>
          <template>
            <p-col :xl="8" :lg="7" :md="8" :sm="24">
              <p-form-item label="产品名称">
                <p-input readonly placeholder="产品名称" disabled v-model="queryParam.mname"></p-input>
              </p-form-item>
            </p-col>
          </template>
          <template>
            <p-col :xl="8" :lg="7" :md="8" :sm="24">
              <p-form-item label="工单数量">
                <p-input readonly placeholder="工单数量" disabled v-model="queryParam.qty"></p-input>
              </p-form-item>
            </p-col>
          </template>
          <p-col :xl="8" :lg="7" :md="8" :sm="24" class="table-operator">
            <p-button type="primary" :span="6" icon="printer" @click="handleAlert">打印</p-button>
            <p-button type="primary" :span="6" icon="printer" @click="handleClick">试打</p-button>
            <p-button type="primary" :span="6" @click="searchQuery" icon="search">搜索</p-button>
            <p-button type="primary" :span="6" icon="printer" @click="myAddHtml">补印</p-button>
          </p-col>
          <template>
            <p-col :xl="8" :lg="7" :md="8" :sm="24">
              <p-form-item label="补印份数">
                <p-input placeholder="请输入补印数量" v-model="queryParam.fileAddNumber"></p-input>
              </p-form-item>
            </p-col>
          </template>
        </p-row>
      </p-form>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>

        <span style="float:right;">
          <p-divider type="vertical" />
          <a @click="loadData()">
            <p-icon type="sync" />刷新
          </a>
          <p-divider type="vertical" />
          <p-popover title="自定义列" trigger="click" placement="leftBottom" :overlay-style="getWidth">
            <template slot="content">
              <p-checkbox-group
                @change="onColSettingsChange"
                v-model="settingColumns"
                :defaultValue="settingColumns"
              >
                <p-row>
                  <template v-for="(item,index) in defColumns">
                    <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                      <p-col :span="12" :key="index">
                        <p-checkbox :value="item.dataIndex">{{ item.title }}</p-checkbox>
                      </p-col>
                    </template>
                  </template>
                </p-row>
              </p-checkbox-group>
            </template>
            <a>
              <p-icon type="setting" />自定义列
            </a>
          </p-popover>
        </span>
      </div>

      <p-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :scroll="tableScroll"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange, type:'radio'}"
        @change="handleTableChange"
      >
        <template slot="status" slot-scope="text, record">
          <f-switch
            v-model="record.status"
            field="record"
            :disabled="true"
            dictCode="mes_status2"
            size="small"
          />
        </template>

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>

          <template slot="labelTemplateLength" slot-scope="text">
          {{ labelTemplateLengthKeys[text]}}
        </template>        

        <template slot="labelType" slot-scope="text">
          {{ labelTypeKeys[text]}}
        </template>

        <template slot="labelColor" slot-scope="text">
          {{ labelColorKeys[text]}}
        </template>

        <template slot="labelColor" slot-scope="text">
          {{ labelColorKeys[text]}}
        </template>

        <template slot="ribbonsType" slot-scope="text">
          {{ ribbonsTypeKeys[text]}}
        </template>

        <template slot="printerType" slot-scope="text">
          {{ printerTypeKeys[text]}}
        </template>

        <template slot="containSn" slot-scope="text">
          {{ containSnKeys[text]}}
        </template>



        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无此图片</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt="图片不存在"
            style="max-width:80px;font-size: 12px;font-style: italic;"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无此文件</span>
          <p-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)"
          >下载</p-button>
        </template>
      </p-table>
    </div>

    <p-tabs defaultActiveKey="1">
      <p-tab-pane tab="条码明细" key="1">
        <mes-bc-supper-field-list :mainId="mainId" @fromChild="getChild" />
      </p-tab-pane>
    </p-tabs>

    <mesBcField-modal ref="modalForm" :EnhanceJS="EnhanceJS" @modalFormOk="modalFormOk"></mesBcField-modal>
    <!-- 弹出窗 -->
    <!-- <Fx-compontens-modal
      @ok="modalFormOk"
      ref="modalCompon"
      :getList="queryInfo"
      :title="title"
      :dictOptions="dictOptions"
    ></Fx-compontens-modal>-->

    <p-modal
      id="alertText"
      title="Title"
      :visible="visible"
      :confirm-loading="confirmLoading"
      @ok="handleOk"
      @cancel="handleCancel"
    >{{$AlertTxt}}</p-modal>
  </p-card>
</template>

<script>
import { JeecgListMixin } from "@/mixins/JeecgListMixin";
import { api } from "@/api/manage";
import {ajaxGetDictItems} from "@/api/api"
import JSuperQuery from "@/components/jeecg/JSuperQuery.vue";
import { filterObj } from "@/utils/util";
import MesBcFieldModal from "./modules/MesBcFieldModal";
import Vue from "vue";
import MesBcSupperFieldList from "./MesBcSupperFieldList";
import { mapState } from 'vuex'
import moment from 'moment';
import {
  initDictOptions,
  filterMultiDictText,
} from "@/components/dict/JDictSelectUtil";
import ButtonExpHandler from "@/components/jeecgbiz/modules/ButtonExpHandler";
import { postAction, getAction, deleteAction,postActionBasic } from "@/api/manage";
import FxCompontensModal from "@/components/jeecgbiz/FxCompontensModal";

//高级查询modal需要参数
const superQueryFieldList = [
  {
    value: "filedCode",
    text: "字段编码",
    type: "String",
  },
  {
    value: "filedName",
    text: "字段名称",
    type: "String",
  },
  {
    value: "filedType",
    text: "字段属性",
    type: "select",
    dictCode: "mes_filed_type",
  },
  {
    value: "filedLength",
    text: "字段位数",
    type: "int",
  },
  {
    value: "barcodeBinary",
    text: "进制",
    type: "select",
    dictCode: "mes_barcode_binary",
  },
  {
    value: "filedCharacter",
    text: "字段字符",
    type: "String",
  },
  {
    value: "barcodeSource",
    text: "来源",
    type: "select",
    dictCode: "mes_barcode_source",
  },
  {
    value: "filedSample",
    text: "字段示例",
    type: "String",
  },
  {
    value: "filedExplain",
    text: "字段说明",
    type: "String",
  },
  {
    value: "status",
    text: "状态",
    type: "select",
    dictCode: "mes_status2",
  },
  {
    value: "remark",
    text: "备注",
    type: "string",
  },
  {
    value: "createBy",
    text: "创建人",
    type: "string",
  },
  {
    value: "createTime",
    text: "创建日期",
    type: "Date",
  },
  {
    value: "updateBy",
    text: "更新人",
    type: "string",
  },
  {
    value: "updateTime",
    text: "更新日期",
    type: "Date",
  },
];

export default {
  name: "MesBcFieldList",
  mixins: [JeecgListMixin],
  components: {
    JSuperQuery,
    MesBcSupperFieldList,
    FxCompontensModal,
    MesBcFieldModal,
  },
  data() {
    return {
      validatorRules: {
        filedCode: { rules: [{ required: true, message: "请输入字段编码!" }] },
        filedName: { rules: [{ required: false, message: "请输入字段名称!" }] },
        filedType: { rules: [{ required: false, message: "请输入字段属性!" }] },
        filedLength: {
          rules: [{ required: true, message: "请输入字段位数!" }],
        },
        barcodeBinary: {},
        filedCharacter: {
          rules: [{ required: true, message: "请输入字段字符!" }],
        },
        barcodeSource: { rules: [{ required: true, message: "请输入来源!" }] },
        filedSample: {
          rules: [{ required: true, message: "请输入字段示例!" }],
        },
        filedExplain: {},
        status: {},
        remark: {},
      },
      labelTemplateLengthKeys: {},
      labelTypeKeys: {},
      labelColorKeys: {},
      ribbonsTypeKeys: {},
      printerTypeKeys: {},
      containSnKeys: {},
      moment,
      active: "请选择",
      mes_filed_type: [],
      mainId: "",
      AlertTxt: "",
      queryParam: {},
      fieldList: superQueryFieldList,
      superQueryFlag: false,
      loading: false,
      superQueryParams: "",
      description: "关键字段信息管理页面",
      EnhanceJS: {},
      plainOptions: [],
      cgButtonLinkList: [],
      dataSource: [],
      cgButtonList: [],
      title: "", //存表名
      groupTag: [],
      queryInfo: [],
      visible: false,
      code: "",
      // 表头
      columns: [],
      //列设置
      settingColumns: [],
      //列定义
      defColumns: [
        {
          title: "序号",
          align: "center",
          dataIndex: "number",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          },
        },
        {
          title: "产品编码",
          align: "center",
          dataIndex: "mcode",
        },
        {
          title: "产品名称",
          align: "center",
          dataIndex: "mname",
        },
        {
          title: "标签模板编号",
          align: "center",
          dataIndex: "labelTemplateNo",
        },
        {
          title: "标签模板名称",
          align: "center",
          dataIndex: "labelTemplateName",
        },
        {
          title: "标签模板描述",
          align: "center",
          dataIndex: "labelTemplateDescrtion",
        },
        {
          title: "标签模板尺寸",
          align: "center",
          dataIndex: "labelTemplateLength",
          scopedSlots: { customRender: "labelTemplateLength" },
        },
        {
          title: "标签类型",
          align: "center",
          dataIndex: "labelType",
          scopedSlots: { customRender: "labelType" },
        },          
        {
          title: "责任部门",
          align: "center",
          dataIndex: "dptname",
        },
        {
          title: "标签纸颜色",
          align: "center",
          dataIndex: "labelColor",
          scopedSlots: { customRender: "labelColor" },
        },
        {
          title: "碳带型号",
          align: "center",
          dataIndex: "ribbonsType",
          scopedSlots: { customRender: "ribbonsType" },
        },
        {
          title: "打印机型号",
          align: "center",
          dataIndex: "printerType",
          scopedSlots: { customRender: "printerType" },
        },
        {
          title: "是否包含流水号",
          align: "center",
          dataIndex: "containSn",
          scopedSlots: { customRender: "containSn" },
        },
        {
          title: "打印份数",
          align: "center",
          dataIndex: "prtintQty",
        },
        {
          title: "已打印份数",
          align: "center",
          dataIndex: "printNums",
        },
      ],
      url: {
        query: "/mes-code/mesBcProduce/getBcProNoList",
        list: "/mes-code/mesBcProductList/list",
        delete: "/mes-code/mesBcField/delete",
        deleteBatch: "/mes-code/mesBcField/deleteBatch",
        exportXlsUrl: "/mes-code/mesBcField/exportXls",
        importExcelUrl: "/mes-code/mesBcField/importExcel",
        getColumns: "/mes-code/online/cgform/api/getColumns/",
        buttonAction: "/mes-code/online/cgform/api/doButton",
        MesBcSupperFieldList: "/mes-code/mesBcPro/detail",
        AddPrinting:"/mes-code/mesBcPrint"
      },
      dictOptions: {
        filedType: [],
        barcodeBinary: [],
        barcodeSource: [],
        status: [],
      },
      /* 分页参数 */
      ipagination: {
        current: 1,
        pageSize: 10,
        pageSizeOptions: ["10", "20", "50"],
        showTotal: (total, range) => {
          return range[0] + "-" + range[1] + " 共" + total + "条";
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0,
      },
      selectedMainId: "",
    };
  },
  computed: {
    importExcelUrl: function () {
      return `${api.test}${this.url.importExcelUrl}`;
    },
    getWidth: function () {
      if (this.defColumns.length > 14) {
        return { width: "500px" };
      }
    },
    ...mapState({
      userInfo:state => state.user,
    }),

    tableScroll: function () {
      if (this.columns.length > 13) {
        return { x: this.columns.length * 150 - 450 };
      }
    },
  },

  created() {
    this.initColumns();
    this.setdefColumns();
  },
  mounted(){
    this.getObjKeys()
  },

  methods: {
    setdefColumns() {
      if (this.columns.length > 13) {
        let arrLength = this.columns.length - 1;
        this.columns.forEach((item, index) => {
          item["width"] = 130;
        });
        this.columns[0]["width"] = "60px";
        this.columns[0]["fixed"] = "left";
        this.columns[1]["fixed"] = "left";
      }
    },
    handleAlert: function () {
      if(this.selectionRows){
        this.EnhanceJS.getId = this.mainId[0].mesBcProduceId; 
        this.EnhanceJS.active=this.active
        this.EnhanceJS.planqty= this.queryParam.planqty
        this.EnhanceJS.queryParam=this.queryParam
      let length = this.plainOptions.filter((item) => item.checked).length;
      if (this.mainId.length == length) {
        this.$refs.modalForm.add();
        this.$refs.modalForm["getRuleCodeValue"]
          ? this.$refs.modalForm.getRuleCodeValue()
          : "";
        this.$refs.modalForm.title = "提示";
        this.$refs.modalForm.disableSubmit = false;
      } else {
        this.$message.error('请选择全部产品标签');
      }
      }else{
        this.$message.error('请选择工单或标签模板！');
      }
    },
    filterOption(input, option) {
      return (
        option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
      );
    },
    initColumns() {
      //权限过滤（列权限控制时打开，修改第二个参数为授权码前缀）
      //this.defColumns = colAuthFilter(this.defColumns,'testdemo:');

      var key = this.$route.name + ":colsettings";
      let colSettings = Vue.ls.get(key);
      if (colSettings == null || colSettings == undefined) {
        let allSettingColumns = [];
        this.defColumns.forEach(function (item, i, array) {
          allSettingColumns.push(item.dataIndex);
        });
        this.settingColumns = allSettingColumns;
        this.columns = this.defColumns;
      } else {
        this.settingColumns = colSettings;
        const cols = this.defColumns.filter((item) => {
          if (item.key == "rowIndex" || item.dataIndex == "action") {
            return true;
          }
          if (colSettings.includes(item.dataIndex)) {
            return true;
          }
          return false;
        });
        this.columns = cols;
      }
    },
    //列设置更改事件
    onColSettingsChange(checkedValues) {
      var key = this.$route.name + ":colsettings";
      Vue.ls.set(key, checkedValues, 7 * 24 * 60 * 60 * 1000);
      this.settingColumns = checkedValues;
      const cols = this.defColumns.filter((item) => {
        if (item.key == "rowIndex" || item.dataIndex == "action") {
          return true;
        }
        if (this.settingColumns.includes(item.dataIndex)) {
          return true;
        }
        return false;
      });
      this.columns = cols;
    },
    textPrink() {
      // document.getElementById('printIframe').contentWindow.print();
    },
    handleClick() {
      this.$refs.Child.doPrint3();
    },

    //高级查询方法
    handleSuperQuery(arg) {
      if (!arg) {
        this.superQueryParams = "";
        this.superQueryFlag = false;
      } else {
        this.superQueryFlag = true;
        this.superQueryParams = JSON.stringify(arg);
      }
      this.loadData();
    },
    // 获取查询条件
    getQueryParams() {
      let sqp = {};
      if (this.superQueryParams) {
        sqp["superQueryParams"] = encodeURI(this.superQueryParams);
      }
      var newData = {
        mcode: this.queryParam.mcode,
        productionno:this.active,
        pageNo: this.ipagination.current,
        limit: this.ipagination.pageSize,
      };
      return filterObj(newData);
    },

    clickThenSelect(record) {
      return {
        on: {
          click: () => {
            this.onSelectChange(record.id.split(","), [record]);
          },
        },
      };
    },
    onClearSelected() {
      this.selectedRowKeys = [];
      this.selectionRows = [];
      this.selectedMainId = "";
      this.EnhanceJS={}
    },
    onSelectChange(selectedRowKeys, selectionRows) {
      this.selectedMainId = selectedRowKeys[0];
      this.selectedRowKeys = selectedRowKeys;
      this.selectionRows = selectionRows;
      this.EnhanceJS = this.dataSource.find(
        (item) => item.id == this.selectedMainId
      );

      
    },
    loadData(arg) {
      if (!this.url.list) {
        this.$message.error("请设置url.list属性!");
        return;
      }
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1;
      }
      this.onClearSelected();
      var params = this.getQueryParams(); //查询条件
      this.loading = true;
      getAction(this.url.list, params).then((res) => {
        if (res.success) {
          this.dataSource = res.data.records;
          if(this.dataSource.length==1){
            this.selectedRowKeys=[this.dataSource[0].id]
            this.selectionRows = this.dataSource;
            this.EnhanceJS = this.selectionRows[0]
            console.log(this.EnhanceJS)
          }
        }
        if (res.code === 510) {
          this.$message.warning(res.msg);
        }
        this.loading = false;
      });
      getAction(this.url.query, {barcodeType: 0}).then((res) => {
        if (res.code == 0) {
          this.mes_filed_type=res.data
        }
      });
    },
    getChild(checkAll) {
      this.plainOptions = checkAll;
    },
    searchQuery() {
      this.loadData();
    },
    getQuery() {
      var newData = {
        productionno: this.queryParam.productionno,
        barcodeType: 0,
      };
      return filterObj(newData);
    },

    // 选择生产工单，拉取数据
    QueryData(data) {
      this.active = data.productionno;
      this.queryParam = data;
      // this.
      this.loadData()
      var getQuery = this.getQuery(); //查询条件
      getAction(this.url.MesBcSupperFieldList, getQuery).then((res) => {
        if (res.success) {
          this.mainId = res.data;
        }
        if (res.code === 510) {
          this.$message.warning(res.msg);
        }
      });
    },

    showModal() {
      this.visible = true;
    },
    handleOk(e) {
      this.visible = false;
    },
    handleCancel(e) {
      this.visible = false;
    },

    // 弹出窗组件
    showDemoModal() {
      this.$refs.modalCompon.modalShow();
    },
    // 点击btn获取数据
    btnGetData(tableName, title) {
      getAction(`${this.url.getColumns}`, {
        tableName: tableName,
      }).then((res) => {
        if (res.code == 0) {
          this.queryInfo = res.data.columns;
          this.title = title;
          this.dictOptions = res.data.dictOptions;
          this.showDemoModal();
        } else {
          this.$message.warning(res.msg);
        }
      });
    },

    //筛选分组
    getGroupTag(arrList) {
      let arr = [];
      var map = {},
        dest = [];
      arrList.forEach((item, index) => {
        if (item.groupTag) {
          arr.push(item);
        }
      });
      for (var i = 0; i < arr.length; i++) {
        var ai = arr[i];
        if (!map[ai.groupTag]) {
          dest.push({
            groupTag: ai.groupTag,
            name: ai.groupName,
            data: [ai],
          });
          map[ai.groupTag] = ai;
        } else {
          for (var j = 0; j < dest.length; j++) {
            var dj = dest[j];
            if (dj.groupTag == ai.groupTag) {
              dj.data.push(ai);
              break;
            }
          }
        }
      }
      this.groupTag = dest;
    },
    showLinkButton(item, record) {
      let btn = new ButtonExpHandler(item.exp, record);
      return btn.show;
    },
    
    initCgEnhanceJs(enhanceJs) {
      //console.log("--onlineList-js增强",enhanceJs)
      if (enhanceJs) {
        let Obj = eval("(" + enhanceJs + ")");
        this.EnhanceJS = new Obj(getAction, postAction, deleteAction);
        this.cgButtonJsHandler("created");
      } else {
        this.EnhanceJS = "";
      }
    },
    initCgButtonList(btnList) {
      let linkArr = [];
      let buttonArr = [];
      if (btnList && btnList.length > 0) {
        for (let i = 0; i < btnList.length; i++) {
          let temp = btnList[i];
          if (temp.buttonStyle == "button") {
            buttonArr.push(temp);
          } else if (temp.buttonStyle == "link") {
            linkArr.push(temp);
          }
        }
      }
      this.cgButtonLinkList = [...linkArr];
      this.cgButtonList = [...buttonArr];
      console.log("链接增强", this.cgButtonLinkList);
    },
    cgButtonJsHandler(buttonCode) {
      if (this.EnhanceJS[buttonCode]) {
        this.EnhanceJS[buttonCode](this);
      }
    },
    cgButtonActionHandler(buttonCode) {
      //处理自定义button的 需要配置该button自定义sql
      if (!this.selectedRowKeys || this.selectedRowKeys.length == 0) {
        this.$message.warning("请先选中一条记录");
        return false;
      }
      if (this.selectedRowKeys.length > 1) {
        this.$message.warning("请只选中一条记录");
        return false;
      }
      let params = {
        formId: this.code,
        buttonCode: buttonCode,
        dataId: this.selectedRowKeys[0],
      };
      console.log("自定义按钮请求后台参数：", params);
      postAction(this.url.buttonAction, params).then((res) => {
        if (res.success) {
          this.loadData();
          this.$message.success("处理完成!");
        } else {
          this.$message.warning("处理失败!");
        }
      });
    },
    cgButtonLinkHandler(record, buttonCode, optType) {
      if (optType == "js") {
        if (this.EnhanceJS[buttonCode]) {
          this.EnhanceJS[buttonCode](this, record);
        }
      } else if (optType == "action") {
        let params = {
          formId: this.code,
          buttonCode: buttonCode,
          dataId: record.id,
        };
        console.log("自定义按钮link请求后台参数：", params);
        postAction(this.url.buttonAction, params).then((res) => {
          if (res.success) {
            this.loadData();
            this.$message.success("处理完成!");
          } else {
            this.$message.warning("处理失败!");
          }
        });
      }
    },
    // 试打
    handleClick () {
        if(this.EnhanceJS){
          let checked=this.plainOptions.filter((item) => item.checked)
          console.log(this.EnhanceJS)
          if(checked.length==1){
            var id = 'bcIds='+checked[0].id; 
            var href = this.EnhanceJS.ureportAddress +"&"+ id; 
            // var href="http://192.168.6.145/fx-platform/ureport/preview?_u=mysql-%E5%B0%8F%E6%A0%87%E7%AD%BE%E6%B5%8B%E8%AF%95.ureport.xml&"+ id
            this.$router.push({
              path: `/layouts/IframePageRouter?=${href}`,
            })
            this.visible=false
          }else{
            this.$message.warning("请选择一个条码打印");
          }
        }else{
          this.$message.warning("请输入打印份数");
        }
       
    },
    // 补印
    myAddHtml(){
      if(this.EnhanceJS && this.queryParam.fileAddNumber){
          let checked=this.plainOptions.filter((item) => item.checked)
              let data=this.getAddPrinting()
          // postActionBasic(this.url.AddPrinting,data).then((res)=>{
          //   if(res.code==0){
          //     this.$message.success('提交成功');
          //   }else{
          //      this.$message.warning(res.msg);
          //   }
            let dataString=[]
            checked.forEach(item=>{dataString.push(item.id);})
            var id = 'bcIds='+dataString.toString(); 
            var href = this.EnhanceJS.ureportAddress +"&"+ id; 
            // var href="http://192.168.6.145/fx-platform/ureport/preview?_u=mysql-%E5%B0%8F%E6%A0%87%E7%AD%BE%E6%B5%8B%E8%AF%95.ureport.xml&"+ id
            this.$router.push({
              path: `/layouts/IframePageRouter?=${href}`,
            })
            this.visible=false
          // })
        }else{
          this.$message.warning("请输入打印份数");
        }
    },


    // 提交打印记录数据
    getAddPrinting(){
      let aData = new Date();
       this.Data=aData.getFullYear() +"-" +(aData.getMonth() + 1) +"-" +aData.getDate()+" "+aData.getHours()+":"+aData.getMinutes()+":"+aData.getSeconds();
      let data={
         name: this.userInfo.name,//打印人
        //  qty:this.PrintingNumber,//打印份数
         labelTemplateName:this.EnhanceJS.labelTemplateName,//标签模板名称
         labelTemplateNo:this.EnhanceJS.mcode,//标签模板编号
         productionno:this.active,//工单号
         qty:this.queryParam.planqty//工单数量
      }
      return data
    },
    // 数据字典
    getObjKeys(){
      [
        {dictCode: 'mes-label-template-length', keysName: 'labelTemplateLengthKeys'},
        {dictCode: 'mes_label_type', keysName: 'labelTypeKeys'},
        {dictCode: 'mes_label_color', keysName: 'labelColorKeys'},
        {dictCode: 'mes-ribbons-type', keysName: 'ribbonsTypeKeys'},
        {dictCode: 'mes_printer_type', keysName: 'printerTypeKeys'},
        {dictCode: 'ba_yn', keysName: 'containSnKeys'},
      ].forEach( ({dictCode, keysName}) => {
        
        ajaxGetDictItems(dictCode).then( res => {
          const obj = {}
          if(res.success) {
            res.data.forEach( ele => {
              obj[ele.value] = ele.text
            } )  
          }
          this[keysName] = obj
        } )
      } )
    },
    modalFormOk(){
      this.loadData()
    }

    }

};
</script>
<style scoped>
@import "~@assets/less/common.less";
</style>
